package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202409;

public class leetcode20240902 {
    public int maxConsecutiveAnswers(String answerKey,int k){
        int n=answerKey.length();
        int cnt=0,ans=0;
        // T 变为 F
        for(int left=0,right=0;right<n;right++){
            if(answerKey.charAt(right)=='T') cnt++;
            while(cnt>k){
                if(answerKey.charAt(left)=='T'){
                    cnt--;
                }
                left++;
            }
            ans=Math.max(ans,right-left+1);
        }
        cnt=0;
        // F 变为 T
        for(int left=0,right=0;right<n;right++){
            if(answerKey.charAt(right)=='F') cnt++;
            while(cnt>k){
                if(answerKey.charAt(left)=='F'){
                    cnt--;
                }
                left++;
            }
            ans=Math.max(ans,right-left+1);
        }
        return ans;
    }
}
